package grape.composite.rest.appadvertisement.mvc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import grape.composite.service.appadvertisement.query.AppAdvertisementListQuery;
import grape.composite.rest.appadvertisement.form.AppAdvertisementListPageForm;
import grape.composite.rest.appadvertisement.form.AppAdvertisementUpdateForm;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.validation.Valid;
import grape.composite.rest.appadvertisement.form.AppAdvertisementCreateForm;
import grape.composite.rest.appadvertisement.vo.AppAdvertisementVo;
import grape.composite.rest.appadvertisement.mapper.AppAdvertisementWebMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import grape.common.rest.mvc.BaseController;
import grape.composite.service.appadvertisement.po.AppAdvertisement;
import grape.composite.service.appadvertisement.api.IAppAdvertisementService;

/**
 * <p>
 * app广告表 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-03-10
 */
@RestController
@RequestMapping("/composite/appadvertisement")
@Api(tags = "app广告相关接口")
public class AppAdvertisementController extends BaseController<AppAdvertisementVo, AppAdvertisement> {

    @Autowired
    private AppAdvertisementWebMapper currentWebMapper;
    @Autowired
    private IAppAdvertisementService currentService;



     @ApiOperation("添加app广告")
     @PreAuthorize("hasAuthority('appadvertisement:single:create')")
     @PostMapping
     @ResponseStatus(HttpStatus.CREATED)
     public AppAdvertisementVo create(@RequestBody @Valid AppAdvertisementCreateForm cf) {
         AppAdvertisement po = currentWebMapper.formToPo(cf);
         return super.create(po);
     }

     @ApiOperation("根据ID查询app广告")
     @PreAuthorize("hasAuthority('appadvertisement:single:queryById')")
     @GetMapping("/{id}")
     @ResponseStatus(HttpStatus.OK)
     public AppAdvertisementVo queryById(@PathVariable String id) {
         return super.queryById(id);
     }

     @ApiOperation("删除app广告")
     @PreAuthorize("hasAuthority('appadvertisement:single:deleteById')")
     @DeleteMapping("/{id}")
     @ResponseStatus(HttpStatus.NO_CONTENT)
     public boolean deleteById(@PathVariable String id) {
         return super.deleteById(id);
     }

     @ApiOperation("更新app广告")
     @PreAuthorize("hasAuthority('appadvertisement:single:updateById')")
     @PutMapping("/{id}")
     @ResponseStatus(HttpStatus.CREATED)
     public AppAdvertisementVo update(@PathVariable String id,@RequestBody @Valid AppAdvertisementUpdateForm uf) {
         AppAdvertisement po = currentWebMapper.formToPo(uf);
         po.setId(id);
         return super.update(po);
     }

    @ApiOperation("分页查询app广告")
    @PreAuthorize("hasAuthority('appadvertisement:single:listPage')")
    @GetMapping("/listPage")
    @ResponseStatus(HttpStatus.OK)
    public IPage<AppAdvertisementVo> listPage(AppAdvertisementListPageForm listPageForm) {
         AppAdvertisement po = currentWebMapper.formToPo(listPageForm);
        AppAdvertisementListQuery appAdvertisementListQuery = new AppAdvertisementListQuery();
        appAdvertisementListQuery.setPoQuery(po);

        return super.listPage(appAdvertisementListQuery,listPageForm);
     }

}
